import java.util.Arrays;

public class Exec01 {
    public int triangleNumber(int[] nums) {
        // 排序
        Arrays.sort(nums);

        //利用双指针和单调性解决问题
        int longgest = nums.length - 1,sum = 0;
        for(;longgest>=2;longgest--){
            int left = 0,right = longgest-1;
            while(left < right){
                if(nums[left] + nums[right] > nums[longgest]){
                    sum += right - left;
                    right--;
                }else{
                    left++;
                }
            }
        }

        return sum;
    }
}
